package com.money.tracker.auth.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.money.tracker.common.utils.StreamUtil;
import com.money.tracker.auth.entity.SysRoleMenu;
import com.money.tracker.auth.mapper.SysRoleMenuMapper;
import com.money.tracker.auth.service.ISysRoleMenuService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 角色和菜单关联表 服务实现类
 * </p>
 *
 * @author zhangshuai
 * @since 2024-09-27
 */
@Service
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements ISysRoleMenuService {

    @Override
    public List<Long> listByRoleIds(List<Long> roleIds) {
        if (CollectionUtil.isEmpty(roleIds)){
            return List.of();
        }
        // 获取角色和菜单对应关系
        LambdaQueryWrapper<SysRoleMenu> sysUserRoleLambdaQueryWrapper = new LambdaQueryWrapper<SysRoleMenu>()
                .in(SysRoleMenu::getRoleId, roleIds);
        return StreamUtil.toList(this.list(sysUserRoleLambdaQueryWrapper), SysRoleMenu::getMenuId);
    }

}
